package com.clickpaas.workinghours.service.Impl;

import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.d20210220155135.model.*;
import com.clickpaas.workinghours.dao.ProjectDao;
import com.clickpaas.workinghours.entity.ProjectEntity;
import com.clickpaas.workinghours.service.ProjectService;
import com.clickpaas.workinghours.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class ProjectServiceImpl implements ProjectService {
    @Resource
    private ProjectDao projectDao;

    /**
     * 获取项目数据
     *
     * @param projectEntity
     * @return
     */
    @Override
    public List<PMSprojectDTO> getProjectInfo(ProjectEntity projectEntity) {

        List<PMSprojectDTO> reList;
        try {
            if (null == projectEntity || DataInfoUtil.isAllFieldNull(projectEntity)){
                reList = DataInfoUtil.castListCopy(projectDao.queryDataInfo(), PMSprojectDTOPageInfoResponse.class, PMSprojectDTO.class);
            }else {
                reList = DataInfoUtil.castListCopy(projectDao.queryDataInfo(projectEntity), PMSprojectDTOResponse.class, PMSprojectDTO.class);
            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",projectEntity,e);
            return null;
        }
        if (null != reList && reList.size()>0){
            return reList;
        }
        return null;
    }

    /**
     * 项目数据转换为bean
     *
     * @param list
     * @return
     */
    @Override
    public List<ProjectEntity> projectDataConver(List<PMSprojectDTO> list) {
        return DataInfoUtil.castListCopy(list,PMSprojectDTO.class,ProjectEntity.class);
    }
}
